package edu.uts.reekie.designer.model.commands;

import org.eclipse.gef.commands.Command;
import edu.uts.reekie.designer.execution.model.*;
import edu.uts.reekie.designer.model.AbstractConnector;

public class SetConnectorDirectionCommand extends Command {

	int oldDirection = Connector.BIDIRECTIONAL_CONNECTION;
	int newDirection = Connector.UNIDIRECTIONAL_CONNECTION;
	AbstractConnector connector;
	
	public AbstractConnector getConnector(){
		return connector;
	}
	
	public void setConnector(AbstractConnector c){
		this.connector =c ;
	}
	
	public SetConnectorDirectionCommand(int newDirection) {
		super("Change connector direction"); // TODO move to messages file
		
		this.newDirection = newDirection;
	}
	
	public boolean canExecute() {
		if (connector==null)
			return false;
		
		if (connector.getDirection()==newDirection)
			return false;
		
		return true;
	}
	
	public void execute() {
		oldDirection = connector.getDirection();
		connector.setDirection(newDirection);
		
	}
	
	
	public void undo() {
		connector.setDirection(oldDirection);
	}
	
}
